﻿using Acme.SmartWMS.Location;
using Acme.SmartWMS.Location.DefinitionService;
using Acme.SmartWMS.Location.DefinitionService.DTO;
using Microsoft.AspNetCore.Mvc;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;

namespace Acme.SmartWMS.Web.Location
{
    public class DefinitionController : Controller
    {
        /// <summary>
        /// 仓库定义服务类
        /// </summary>
        private readonly IDefinitionAppService _definitionAppService;
        public DefinitionController(IDefinitionAppService definitionAppService)
        {
            _definitionAppService= definitionAppService;
        }
        public IActionResult DefinitionList()
        {
            return View();
        }
        public IActionResult Add()
        {
            return View();
        }
        public IActionResult Update(int id)
        {
            ViewBag.id = id;
            return View();
        }
        /// <summary>
        /// 获取仓库定义分页 显示 查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="warehouseCode"></param>
        /// <param name="warehouseName"></param>
        /// <returns></returns>
        public async Task<JsonResult> GetDefinitionList(int page, int limit, string? warehouseCode, string? warehouseName)
        {
            var definition= await _definitionAppService.GetDefinitionList(page, limit, warehouseCode, warehouseName);
            return Json(new {code=0,data=definition.Queryable,count=definition.RowCount });
        }
        /// <summary>
        /// 添加仓库定义
        /// </summary>
        /// <param name="definitionDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> InsertDefinition(DefinitionDTO definitionDTO)
        {
            return await _definitionAppService.InsertDefinition(definitionDTO);
        }
        /// <summary>
        /// 删除仓库定义
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<int> DeleteDefinition(string ids)
        {
            return await _definitionAppService.DeleteDefinition(ids);
        }
        /// <summary>
        /// 获取仓库定义主键Id
        /// </summary>
        /// <param name="id"></para
        [HttpGet]
        public async Task<Definition> GetDefinitionById(int id)
        {
            ViewBag.id = id;
            return await  _definitionAppService.GetDefinitionById(id);
        }
        /// <summary>
        /// 更新仓库定义
        /// </summary>
        /// <param name="definitionDTO"></param
        [HttpPost]
        public async Task<int> UpdateDefinition(DefinitionDTO definitionDTO)
        {
            return await _definitionAppService.UpdateDefinition(definitionDTO);
        }
    }
}
